<%--
    Document   : VMCompany
    Created on : 30/05/2010, 20:08:22
    Author     : TIAGO
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="br.terminalrodoviario.*"%>
<%@page import="java.util.*, java.text.*" %>
<jsp:useBean class="br.terminalrodoviario.Company" id="Company" scope="page"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Guia Terminal Rodoviário</title>
        <style type="text/css" rel="stylesheet">
            @import url("add/css/cssAdmin.css");
            @import url("add/css/cod.css");
            @import url("add/css/rodape.css");
        </style>        
    </head>

    <body>

        <div class="geral">
            <table>
                <tr>
                    <td>
                        <div id="cabecalho"></div>
                    </td>
                </tr>
            </table>
            <div align="right" style="font-family:calibri; font-size:13px;"><a href="Company/login.jsp">Área Restrita</a>&nbsp;&nbsp;&nbsp;</div>
            <table>
                <tr>
                    <td>
                        <div>
                            <ul class="menu">
                                <li><a href="index.jsp"><b>início</b></a></li>
                                <li class="current"><a href="VMCompany.jsp"><b>empresas</b></a></li>
                                <li><a href="VMBusStation.jsp"><b>terminais rodoviários</b></a></li>
                                <li><a href="VMHotel.jsp"><b>hotéis</b></a></li>
                                <li><a href="VMNotice.jsp"><b>notícias</b></a></li>
                                <li><a href="VMTravelTip.jsp"><b>dicas de viagem</b></a></li>
                            </ul>
                        </div>
                    </td>

                </tr>
            </table>
            <br/>
            <form action="../CompanyServlet" method="get">
                <div id="conteudo" align="center">
                    <%SimpleDateFormat fmt = new SimpleDateFormat("HH:mm");
                                String ft = "###,##0.00";
                                DecimalFormat myFormatter = new DecimalFormat(ft);
                                DecimalFormatSymbols dfs = new DecimalFormatSymbols(new Locale("pt", "BR"));
                                dfs.setMonetaryDecimalSeparator('.');
                                myFormatter.setDecimalFormatSymbols(dfs);
                    %>
                    <%

                                if (request.getParameter("cboCityFrom") != null && request.getParameter("cboCityTo") != null) {
                                    City from = (City) new City().select("select c from City c where c.id=" + request.getParameter("cboCityFrom")).toArray()[0];
                                    City to = (City) new City().select("select c from City c where c.id=" + request.getParameter("cboCityTo")).toArray()[0];
                    %>
                    <div align="center" style="font-family:calibri;font-size:13px;">
                        <table>
                            <tr>
                                <td class="label_bg" style="width:75px" align="center">
                                    <b>De:</b>
                                </td>
                                <td>
                                    <%=from.getFullName()%>
                                </td>
                                <td class="label_bg" style="width:75px" align="center">
                                    <b>Para:</b>
                                </td>
                                <td>
                                    <%=to.getFullName()%>
                                </td>
                            </tr>
                        </table>
                    </div> 
                    <%
                                                ArrayList<RouteTime> lst = new Search(from, to).getRoutes();
                                                Object[] routes = lst.toArray();
                                                if (routes.length > 0) {
                    %>
                    <br/>
                    <table border="0" width="750" cellspacing="0" cellpadding="0" style="font-family:calibri">
                        <tr class="table_header">                            
                            <th align="left">Rota</th>
                            <th align="center">Partida</th>
                            <th align="center">Chegada</th>
                            <th align="center">Preço</th>
                            <th align="center">Tipo</th>
                            <th align="center">Empresa</th>
                        </tr>
                        <%
                                                        for (int i = 0; i < routes.length; i++) {
                                                            RouteTime n = (RouteTime) routes[i];
                        %>
                        <tr class="<%=(i % 2 != 0) ? "table_row_bgcolor" : "table_row"%>" >
                            <td align="left" height="30"><%=n.getRouteTravel().getRoute().getType() == 1 ? n.getRouteTravel().getRoute().getFrom().getFullName() : n.getRouteTravel().getRoute().getTo().getFullName()%> - <%=n.getRouteTravel().getRoute().getType() == 1 ? n.getRouteTravel().getRoute().getTo().getFullName() : n.getRouteTravel().getRoute().getFrom().getFullName()%></td>
                            <td align="center"><%=fmt.format(n.getTime())%></td>
                            <td align="center"><%=fmt.format(n.getArrival())%></td>
                            <td align="center"><%=n.getPrice() > 0 ? "R$ " + myFormatter.format(n.getPrice()) : "---"%></td>
                            <td align="center"><%=n.getRouteTravel().getRoute().getRouteType().getName()%></td>
                            <td align="center">
                                <a href="VFCompany.jsp?id=<%=n.getRouteTravel().getRoute().getCompany().getId()%>">
                                <%  if (n.getRouteTravel().getRoute().getCompany().getLogo() != null) {
                                %>
                                <img src="add/images/companies/<%=n.getRouteTravel().getRoute().getCompany().getLogo()%>" border="0" alt="<%=n.getRouteTravel().getRoute().getCompany().getName()%>" />
                                <%
                                  } else {
                                %>
                                <%=n.getRouteTravel().getRoute().getCompany().getName()%>
                                <%
                                                                    }
                                %>
                                </a>
                            </td>
                        </tr>
                            <tr>
                                <td colspan="6" style="height: 5px; background-image: url(add/images/pontilhado.png);background-repeat: repeat-x;"></td>
                            </tr>
                        <%
                                                        }
                        %>                        
                    </table>
                    <%
                                                } else {
                    %>
                    <br/>
                    <b>Não foi encontrada nenhuma rota.</b>
                    <%                                        }
                                }
                    %>
                </div>
            </form>

            <br/><br/>

            <table id="rodape" style="background-image:url(add/images/rodape.png);">
                <tr>
                </tr>
            </table>
            <table id="btRodape" style="text-decoration: none;" >
                <tr>
                    <td align="center" width="80px">
                        <ul class="btYoutube">
                            <li><a title="Youtube" href="http://www.youtube.com" /></li>
                        </ul>
                    </td >
                    <td align="center" width="80px">
                        <ul class="btOrkut">
                            <li><a title="Orkut" href="http://www.orkut.com" /></li>
                        </ul>
                    </td>
                    <td align="center" width="205px">
                        <ul class="btTwitter">
                            <li><a title="Twitter" href="http://twitter.com" /></li>
                        </ul>
                    </td>
                    <td align="center">
                        <a title="Trabalhe Conosco" class="text" href="Carrer.jsp" >Trabalhe Conosco</a>
                    </td>
                    <td align="center"  width="">
                        <a title="Mapa do Site" class="text" href="SiteMap.jsp">Mapa do Site</a>
                    </td>
                    <td align="center" width="">
                        <a title="Contatos" class="text" href="Contact.jsp">Contatos</a>
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>
